//
//  CompleteTypeView.m
//  OperationPro
//
//  Created by yaxue wang on 2017/2/17.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "CompleteTypeView.h"
#import "BankView.h"
#import "LoadingView.h"
@interface CompleteTypeView()

//@property (nonatomic, strong)NSMutableArray *typeAr;
@property (nonatomic, strong) void(^action)(CompleteTypeView *, NSInteger);
@property (nonatomic, strong) UIView *boxView;
@property (nonatomic, strong) NSString *type;
@property (nonatomic, strong) NSString *typeStr;
@end
@implementation CompleteTypeView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        
    }
    return self;
}

+(CompleteTypeView *) showTypeAr:(NSMutableArray*)typeAr Action:(void(^)(CompleteTypeView *boxView, NSInteger index))action
{
    
   CompleteTypeView *boxView = [[CompleteTypeView alloc] init];
    boxView.action = action;
//    boxView.typeAr=typeAr;
    [boxView showBox];
    return boxView;
}

- (void) initView{
  

    [[LoadingView shareLoading] startAnimating];

    [CClass HttpRequestTask:YES withUrl:@"select_showFaultTypeSelect" withData:nil notifyError:YES onSuccess:^(BaseModel *model) {
   UIView*bgView=  [self headViewWith:(NSMutableArray*)model.B_data];
        [self addSubview:bgView];
        [[LoadingView shareLoading] stopAnimating];

    } onError:^(BaseModel *model) {
        
    }];
    
  

    
    
    
    
}
- (UIView*)headViewWith:(NSMutableArray *)typeAr
{
    NSDictionary *dic =[typeAr objectAtIndex:0];
    _typeStr=[dic objectForKey:@"type_name"];
    _type=[dic objectForKey:@"uuid"];
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    [bgView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.6]];
    [bgView bk_whenTapped:^{
        [self hideBox];
    }];
    CGFloat height=40*typeAr.count+0.5*(typeAr.count+1);
    UIView *whiteView=[[UIView alloc]initWithFrame:CGRectMake(0, WindowHeight-height, WindowWidth,height)];
    whiteView.backgroundColor=[UIColor whiteColor];
    [bgView addSubview: whiteView];
    for (int i=0; i<typeAr.count; i++) {
        NSDictionary *dic =[typeAr objectAtIndex:i];
        UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, 0+40.5*i, WindowWidth, 0.5)];
        [whiteView addSubview:line];
        if (i==0||i==typeAr.count-1) {
            line.backgroundColor=LineColor;
        }else
        {
            line.backgroundColor=LineColor;
        }
        UILabel *contextLab=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame), WindowWidth,40)];
        contextLab.text=[dic objectForKey:@"type_name"];
        contextLab.textAlignment=NSTextAlignmentCenter;
        contextLab.userInteractionEnabled=YES;
        [contextLab bk_whenTapped:^{
            _typeStr=[dic objectForKey:@"type_name"];
            _type=[dic objectForKey:@"uuid"];
            self.action(self, 1);
            [self hideBox];
        }];
        contextLab.font=F(15);
        contextLab.textColor=FontColor;
        [whiteView addSubview:contextLab];
    }
    return bgView;

}
- (id)typeData
{
    return _type;
}

- (void) showBox{
    [self initView];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
}

- (void) hideBox{
    [self removeFromSuperview];
}
//- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
//{
//    return 1;
//    
//}
//- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
//{
//    return 35;
//}
//
//- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
//{
//    
//    return _typeAr.count;
//    
//}
//-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//{
//    
//    NSDictionary *dic =[_typeAr objectAtIndex:row];
//    return [dic objectForKey:@"type_name"];
//    
//    
//}
//-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
//{
//    
//
//    
//}

@end
